package io.renren.modules.app.entity;


import com.fasterxml.jackson.annotation.JsonFormat;
import org.apache.commons.lang.StringUtils;

import java.util.Date;
import java.util.regex.Pattern;

/**
 * @Auther zxl
 * @Date 2019/1/4 0:02
 * @Description  行驶证识别得到的信息
 **/
public class VehicleEntity {



    private Long userId;

    /**
     * 车牌号
     */
    private String plate_num;

    /**
     * 车辆类型
     */
    private String vehicle_type;

    /**
     * 所有人名称
     */
    private String owner;

    /**
     * 使用性质
     */
    private String use_character;

    /**
     * 地址
     */
    private String addr;

    /**
     * 品牌型号
     */
    private String model;

    /**
     * 车辆识别代号
     */
    private String vin;

    /**
     * 发动机号码
     */
    private String engine_num;

    /**
     * 注册时间
     */
    @JsonFormat(pattern="yyyy-MM-dd")
    private Date register_date;

    /**
     * 发证日期
     */
    @JsonFormat(pattern="yyyy-MM-dd")
    private Date issue_date;

//    请求对应的唯一表示
    private String request_id;

    private boolean success;

    public VehicleEntity(){}

    public VehicleEntity(String plate_num, String vehicle_type, String owner, String use_character,
                         String addr, String model, String vin, String engine_num, Date register_date,
                         Date issue_date,boolean success) {
        this.plate_num = plate_num;
        this.vehicle_type = vehicle_type;
        this.owner = owner;
        this.use_character = use_character;
        this.addr = addr;
        this.model = model;
        this.vin = vin;
        this.engine_num = engine_num;
        this.register_date = register_date;
        this.issue_date = issue_date;
        this.success=true;
    }

    /**
     * 校验车牌号
     * @return
     */
    public boolean checkplateNum(){
        if (StringUtils.isBlank(this.plate_num)){
            return false;
        }
        String pattern = "([京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼]{1}(([A-HJ-Z]{1}[A-HJ-NP-Z0-9]{5})|([A-HJ-Z]{1}(([DF]{1}[A-HJ-NP-Z0-9]{1}[0-9]{4})|([0-9]{5}[DF]{1})))|([A-HJ-Z]{1}[A-D0-9]{1}[0-9]{3}警)))|([0-9]{6}使)|((([沪粤川云桂鄂陕蒙藏黑辽渝]{1}A)|鲁B|闽D|蒙E|蒙H)[0-9]{4}领)|(WJ[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼·•]{1}[0-9]{4}[TDSHBXJ0-9]{1})|([VKHBSLJNGCE]{1}[A-DJ-PR-TVY]{1}[0-9]{5})";
        return Pattern.matches(pattern, this.plate_num);
    }

    /**
     * 校验车辆识别代号
     * @return
     */
    public boolean checkVin(){
        return StringUtils.isNotBlank(this.vin) && this.vin.length()==17;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public String getPlate_num() {
        return plate_num;
    }

    public void setPlate_num(String plate_num) {
        this.plate_num = plate_num;
    }

    public String getVehicle_type() {
        return vehicle_type;
    }

    public void setVehicle_type(String vehicle_type) {
        this.vehicle_type = vehicle_type;
    }

    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }

    public String getUse_character() {
        return use_character;
    }

    public void setUse_character(String use_character) {
        this.use_character = use_character;
    }

    public String getAddr() {
        return addr;
    }

    public void setAddr(String addr) {
        this.addr = addr;
    }

    public String getModel() {
        return model;
    }

    public void setModel(String model) {
        this.model = model;
    }

    public String getVin() {
        return vin;
    }

    public void setVin(String vin) {
        this.vin = vin;
    }

    public String getEngine_num() {
        return engine_num;
    }

    public void setEngine_num(String engine_num) {
        this.engine_num = engine_num;
    }

    public Date getRegister_date() {
        return register_date;
    }

    public void setRegister_date(Date register_date) {
        this.register_date = register_date;
    }

    public Date getIssue_date() {
        return issue_date;
    }

    public void setIssue_date(Date issue_date) {
        this.issue_date = issue_date;
    }

    public String getRequest_id() {
        return request_id;
    }

    public void setRequest_id(String request_id) {
        this.request_id = request_id;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    @Override
    public String toString() {
        return "VehicleEntity{" +
                "userId=" + userId +
                ", plate_num='" + plate_num + '\'' +
                ", vehicle_type='" + vehicle_type + '\'' +
                ", owner='" + owner + '\'' +
                ", use_character='" + use_character + '\'' +
                ", addr='" + addr + '\'' +
                ", model='" + model + '\'' +
                ", vin='" + vin + '\'' +
                ", engine_num='" + engine_num + '\'' +
                ", register_date=" + register_date +
                ", issue_date=" + issue_date +
                ", request_id='" + request_id + '\'' +
                ", success=" + success +
                '}';
    }
}
